//
// Created by Incredible on 17/3/21.
//

#ifndef UNIONFIND2_UNIONFINDTESTHELPER_H
#define UNIONFIND2_UNIONFINDTESTHELPER_H


class UnionFind;

#include <iostream>
#include <cassert>
#include "UnionFind1.h"
#include "UnionFind2.h"
#include "UnionFind3.h"
#include "UnionFind4.h"
#include "UnionFind5.h"
#include "UnionFind6.h"

using namespace std;

namespace UnionFindTestHelper {

    void testUnionFind1(int n) {

        UF1::UnionFind unionFind = UF1::UnionFind(n);

        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }

        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        cout << "testUnionFind1 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }

    void testUnionFind2(int n) {

        UF2::UnionFind unionFind = UF2::UnionFind(n);

        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }

        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        cout << "testUnionFind2 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }


    void testUnionFind3(int n) {

        UF3::UnionFind unionFind = UF3::UnionFind(n);

        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }

        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        cout << "testUnionFind3 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }

    void testUnionFind4(int n) {

        UF4::UnionFind unionFind = UF4::UnionFind(n);
        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }
        cout<<endl;
        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }
        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }
        cout<<endl;
        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }
        cout<<endl;

        cout << "testUnionFind4 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }

    void testUnionFind5(int n) {

        UF5::UnionFind unionFind = UF5::UnionFind(n);

        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }

        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        cout << "testUnionFind5 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }

    void testUnionFind6(int n) {

        UF6::UnionFind unionFind = UF6::UnionFind(n);

        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }

        cout << endl;
        srand(time(NULL));
        clock_t startTime = clock(); //时钟周期数
        //随机挑选n对数据进行联合
        for (int i = 0; i < n; i++) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.unionElements(x, y);
        }

        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }

        cout << endl;


        //随机挑选n对数据进行联系判断
        for (int j = 0; j < n; ++j) {
            int x = rand() % n;
            int y = rand() % n;
            unionFind.isConnection(x, y);
        }
        clock_t endTime = clock();

        for (int k = 0; k < n; ++k) {
            cout << *(unionFind.rank + k) << " ";
        }

        cout << endl;
        cout << "testUnionFind6 : " << 2 * n << " ops(操作次数) " << " 耗时 : "
             << double(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;

    }
};

#endif //UNIONFIND2_UNIONFINDTESTHELPER_H
